package com.cloudfun.campusshare.configuration.property;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * Created by Huqin on 2020/7/31
 */
@Data
@Component
@ConfigurationProperties(prefix = "kjt")
public class KjtProperties implements InitializingBean {

    private String gatewayUrl;

    /**
     * 快捷通公钥
     */
    private String publicKey;

    private String gandaoMerchantId;

    private String notifyUrl;

    private String returnUrl;

    private String subMerchantReturnUrl;

    private SftpProperties sftp;

    @Data
    public static class SftpProperties {
        private String host;
        private Integer port;
        private String username;
        private String password;
        /**
         * 影印件路径
         */
        private String photoCopyPath;
        /**
         * 对账单路径
         */
        private String statementPath;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if (StringUtils.isBlank(gatewayUrl) || StringUtils.isBlank(publicKey) || StringUtils.isBlank(gandaoMerchantId)||StringUtils.isBlank(notifyUrl)||StringUtils.isBlank(subMerchantReturnUrl)) {
            throw new RuntimeException("快捷通配置异常，请检查配置");
        }
        if (StringUtils.isBlank(sftp.getHost()) || null == sftp.getPort() || StringUtils.isBlank(sftp.getUsername())
                || StringUtils.isBlank(sftp.getPassword()) || StringUtils.isBlank(sftp.getPhotoCopyPath()) || StringUtils.isBlank(sftp.getStatementPath())) {
            throw new RuntimeException("快捷通配置异常，请检查配置");
        }
    }
}
